package tech.edwardvan.designpattern.pattern.creational.abstractfactory;

import lombok.extern.slf4j.Slf4j;

/**
 * 抽象工厂模式
 * <p>
 * 当一个产品族中的多个对象被设计成一起工作时,它能够保证客户端始终只使用同一个产品族中的对象
 *
 * @author EdwardVan
 */
@Slf4j
public class AbstractFactoryDemo {

    public static void main(String[] args) {
        ComputerFactory computerFactory = new MsiComputerFactory();
        GPU gpu = computerFactory.produceGPU();
        gpu.output();
        RAM ram = computerFactory.produceRAM();
        ram.read();
    }

    private interface ComputerFactory {
        GPU produceGPU();

        RAM produceRAM();
    }

    private static class MsiComputerFactory implements ComputerFactory {

        @Override
        public GPU produceGPU() {
            return new MsiGPU();
        }

        @Override
        public RAM produceRAM() {
            return new MsiRAM();
        }
    }

    private static class ColorfulComputerFactory implements ComputerFactory {

        @Override
        public GPU produceGPU() {
            return new ColorfulGPU();
        }

        @Override
        public RAM produceRAM() {
            return new ColorfulRAM();
        }
    }

    /**
     * 显卡
     */
    private interface GPU {
        void output();
    }

    private static class MsiGPU implements GPU {

        @Override
        public void output() {
            log.info("微星显卡输出");
        }
    }

    private static class ColorfulGPU implements GPU {

        @Override
        public void output() {
            log.info("七彩虹显卡输出");
        }
    }

    /**
     * 内存
     */
    private interface RAM {
        void read();
    }

    private static class MsiRAM implements RAM {

        @Override
        public void read() {
            log.info("微星内存读取");
        }
    }

    private static class ColorfulRAM implements RAM {

        @Override
        public void read() {
            log.info("七彩虹内存读取");
        }
    }
}
